package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "自媒体用户API", tags = "自媒体用户API")
@RestController
@RequestMapping("/api/v1/user/findByName/{name}")
public class WmUserController {
    @Autowired
    WmUserService wmUserService;

    @ApiOperation(value = "保存自媒体用户信息")
    @PostMapping("/save")
    public ResponseResult<WmUser> save(@RequestBody WmUser user) {
        wmUserService.save(user);
        return ResponseResult.okResult(user);
    }

    @ApiOperation(value = "根据名称查询信息")
    @PostMapping("/findByName/{name}")
    public ResponseResult<WmUser> findByName(@PathVariable("name") String name) {
        LambdaQueryWrapper<WmUser> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(WmUser::getName, name);
        WmUser user = wmUserService.getOne(wrapper);
        return ResponseResult.okResult(user);
    }
    @ApiOperation("根据id查询自媒体用户信息")
    @GetMapping("/findOne/{id}")
    public ResponseResult<WmUser> findWmUserById(@PathVariable("id") Integer id) {
        return ResponseResult.okResult(wmUserService.getById(id));
    }

}
